package com.woniu.secondhand.controller;

import com.woniu.common.annotation.LoginUser;
import com.woniu.common.entity.Result;
import com.woniu.secondhand.entity.dto.CommentAddDTO;
import com.woniu.secondhand.pojo.SecondhandComment;
import com.woniu.secondhand.service.ISecondhandCommentService;
import com.woniu.user.vo.UserLoginVO;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import lombok.extern.slf4j.Slf4j;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

/**
 * <p>
 * 前端控制器
 * </p>
 *
 * @author HMMT
 * @since 2023-05-20
 */
@RestController
@RequestMapping("/secondhandComment")
@Api(tags = "评论管理")
@Slf4j
public class SecondhandCommentController {
    @Autowired
    private ISecondhandCommentService commentService;

    @GetMapping("/{userId}/{productId}")
    @ApiOperation("根据userId和productId获取单个的评论对象")
    public Result<SecondhandComment> getByUserIdAndProductId(@PathVariable Integer userId, @PathVariable Integer productId) {
        SecondhandComment comment = commentService.getByUserIdAndProductId(userId, productId);
        return Result.ok(comment);
    }

    @PostMapping("/add")
    @ApiOperation("新增一条评论")
    public Result<SecondhandComment> addComment(@RequestBody CommentAddDTO commentAddDTO, @LoginUser UserLoginVO userLoginVO) {
        SecondhandComment comment = commentService.addComment(commentAddDTO, userLoginVO);
        return Result.ok(comment);
    }
}
